//
//  BKXXSQTableViewCell.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/24.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "BKXXSQTableViewCell.h"

@implementation BKXXSQTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initSubView];
    }
    return self;
}
- (void)initSubView{
    [self addSubview:self.startLabel];
    [self addSubview:self.dianMingButton];
    [self addSubview:self.applayNumberLabel];
    [self addSubview:self.endLabel];
    
    
    
    [_startLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@20);
        make.centerY.equalTo(self.mas_centerY);
        make.right.equalTo(self.mas_centerX);
        make.height.equalTo(@20);
    }];
    [_dianMingButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@0).offset(-20);
        make.centerY.equalTo(self.mas_centerY);
        make.width.equalTo(@60);
        make.height.equalTo(@25);
    }];
    [_applayNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self->_dianMingButton.mas_left).offset(-27);
        make.centerY.equalTo(self.mas_centerY);
        make.width.equalTo(@100);
        make.height.equalTo(@20);
    }];
    [_endLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self->_applayNumberLabel.mas_left).offset(-19);
        make.centerY.equalTo(self.mas_centerY);
        make.width.equalTo(@100);
        make.height.equalTo(@20);
    }];
    [self layoutTypeBottom];
    
}
//- (void)layoutTypeTop{
//    [_dianMingButton setTitle:@"点名" forState:UIControlStateNormal];
//    _dianMingButton.titleLabel.font = [UIFont systemFontOfSize:14];
//    [_dianMingButton setBackgroundImage:[UIImage imageWithColor:SELECTEDCOLOR forSize:CGSizeMake(100, 100)] forState:UIControlStateNormal];
//    [_dianMingButton setBackgroundImage:[UIImage imageWithColor:LINCOLOR forSize:CGSizeMake(100, 100)] forState:UIControlStateHighlighted];
//    [_dianMingButton mas_updateConstraints:^(MASConstraintMaker *make) {
//        make.right.equalTo(@0).offset(-20);
//        make.centerY.equalTo(self.mas_centerY);
//        make.width.equalTo(@60);
//        make.height.equalTo(@25);
//    }];
//    [_dianMingButton addTarget:self action:@selector(dianMingButtonVClick:) forControlEvents:UIControlEventTouchUpInside];
//}
- (void)layoutTypeBottom{
    [_dianMingButton setTitle:@"" forState:UIControlStateNormal];
    [_dianMingButton setBackgroundImage:[UIImage imageNamed:@"sx_xiaozu_chakan"] forState:UIControlStateNormal];
    [_dianMingButton setBackgroundImage:[UIImage imageNamed:@"sx_xiaozu_chakan"] forState:UIControlStateHighlighted];
    [_dianMingButton mas_updateConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@0).offset(-20);
        make.centerY.equalTo(self.mas_centerY);
        make.width.equalTo(@20);
        make.height.equalTo(@15);
    }];
    [_dianMingButton addTarget:self action:@selector(checkButtonVClick:) forControlEvents:UIControlEventTouchUpInside];
}
- (UILabel *)startLabel{
    if (!_startLabel) {
        UILabel *label = [[UILabel alloc]init];
        label.text  = @"课时：2019-04-05 17：02-18：09";
        label.font = [UIFont systemFontOfSize:14];
        label.textColor = TITLECOLOR;
        label.textAlignment = 0;
        label.attributedText = [PublickFunctionObject getPriceAttribute:label.text and:SELECTEDCOLOR andChangeBenginString:@"：" andEndString:@"" andSize:14];
        _startLabel = label;
    }
    return _startLabel;
}
- (UILabel *)endLabel{
    if (!_endLabel) {
        UILabel *label = [[UILabel alloc]init];
        label.text  = @"申请人数：20";
        label.font = [UIFont systemFontOfSize:14];
        label.textColor = TITLECOLOR;
        label.textAlignment = 0;
        label.attributedText = [PublickFunctionObject getPriceAttribute:label.text and:SELECTEDCOLOR andChangeBenginString:@"：" andEndString:@"" andSize:14];
        _endLabel = label;
    }
    return _endLabel;
}
- (UILabel *)applayNumberLabel{
    if (!_applayNumberLabel) {
        UILabel *label = [[UILabel alloc]init];
        label.text  = @"实到人数：20";
        label.font = [UIFont systemFontOfSize:14];
        label.textColor = TITLECOLOR;
        label.textAlignment = 0;
        label.attributedText = [PublickFunctionObject getPriceAttribute:label.text and:SELECTEDCOLOR andChangeBenginString:@"：" andEndString:@"" andSize:14];
        _applayNumberLabel = label;
    }
    return _applayNumberLabel;
}
- (UIButton *)dianMingButton{
    if (!_dianMingButton) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:@"点名" forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:14];
        [button setBackgroundImage:[UIImage imageWithColor:SELECTEDCOLOR forSize:CGSizeMake(100, 100)] forState:UIControlStateNormal];
        [button setBackgroundImage:[UIImage imageWithColor:LINCOLOR forSize:CGSizeMake(100, 100)] forState:UIControlStateHighlighted];
        
        button.layer.cornerRadius = 5;
        button.layer.masksToBounds = YES;
        _dianMingButton = button;
    }
    return _dianMingButton;
}
- (void)dianMingButtonVClick:(UIButton *)sender{
    self.block(self.indexPath);
}
- (void)checkButtonVClick:(UIButton *)sender{
    self.checkBlock(self.indexPath);
}
- (void)drawRect:(CGRect)rect{
    UIBezierPath *path = [[UIBezierPath alloc]init];
    [path moveToPoint:CGPointMake(0, 40)];
    [path addLineToPoint:CGPointMake(self.frame.size.width, 40)];
    [path setLineWidth:1];
    [LINCOLOR setStroke];
    [path stroke];
    
    UIBezierPath *pathLeft = [[UIBezierPath alloc]init];
    [pathLeft moveToPoint:CGPointMake(0, 0)];
    [pathLeft addLineToPoint:CGPointMake(0, 40)];
    [pathLeft setLineWidth:1];
    [LINCOLOR setStroke];
    [pathLeft stroke];
    
    UIBezierPath *pathRight = [[UIBezierPath alloc]init];
    [pathRight moveToPoint:CGPointMake(self.frame.size.width, 0)];
    [pathRight addLineToPoint:CGPointMake(self.frame.size.width, 40)];
    [pathRight setLineWidth:1];
    [LINCOLOR setStroke];
    [pathRight stroke];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (void)setStartLabelValue:(NSString *)content{
    NSString *string = [NSString stringWithFormat:@"课时：%@",content];
    NSMutableAttributedString *Astring = [[NSMutableAttributedString alloc] initWithString:string attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang-SC-Regular" size: 14],NSForegroundColorAttributeName: TITLECOLOR}];
    NSRange range = [string rangeOfString:@"："];
    [Astring addAttributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang-SC-Regular" size: 14]} range:NSMakeRange(0,range.location-1)];
    NSRange range1 = [string rangeOfString:@" "];
    [Astring addAttributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang-SC-Regular" size: 14], NSForegroundColorAttributeName: [UIColor colorWithRed:32/255.0 green:176/255.0 blue:151/255.0 alpha:1.0]} range:NSMakeRange(range.location+1, range1.location-1)];
    [Astring addAttributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang-SC-Regular" size: 14], NSForegroundColorAttributeName: [UIColor redColor]} range:NSMakeRange(range1.location+1,string.length-range1.location-1)];
    self.startLabel.attributedText = Astring;
}
- (void)setApplayNumberLabelValue:(NSString *)content{
    NSString *string = [NSString stringWithFormat:@"实到人数：%@",content];
    _applayNumberLabel.attributedText = [PublickFunctionObject getPriceAttribute:string and:[UIColor redColor] andChangeBenginString:@"：" andEndString:@"" andSize:14];
}
- (void)setEndLabelValue:(NSString *)content{
    NSString *string = [NSString stringWithFormat:@"申请人数：%@",content];
    _endLabel.attributedText = [PublickFunctionObject getPriceAttribute:string and:[UIColor redColor] andChangeBenginString:@"：" andEndString:@"" andSize:14];
}
@end
